package com.yhny.lykj.yuhannongye.Adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yhny.lykj.yuhannongye.R;
import com.yhny.lykj.yuhannongye.app.BaseRefreshListAdapter;
import com.yhny.lykj.yuhannongye.model.MsgListModel;
import com.yhny.lykj.yuhannongye.tools.LCSysTimeUtils;
import com.yhny.lykj.yuhannongye.tools.Tools;

import java.util.List;


/**
 * MsgListAdapter
 * 消息列表
 */
public class MsgListAdapter extends BaseRefreshListAdapter<MsgListAdapter.ViewHolder> {
    private List<MsgListModel.ListEntity> list;
    private OnItemClickListener listener = null;
    private int selectedPosition = -1;// 选中的位置

    public MsgListAdapter(List<MsgListModel.ListEntity> list) {
        this.list = list;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    protected void onBindBaseViewHolder(ViewHolder holder, int position) {
        MsgListModel.ListEntity entity = list.get(position);
            //后台消息
            holder.titleTv.setText(entity.title);
        holder.infoView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });

        holder.infoView.setText(Tools.HtmlToStr(entity.content));
        holder.order_time.setText(LCSysTimeUtils.getYdmDate(entity.time,1));



    }
    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_msg_list;
    }

    @Override
    protected ViewHolder onCreateBaseViewHolder(View itemView) {
        return new ViewHolder(itemView, listener);
    }


    public static class ViewHolder extends BaseRefreshListAdapter.ViewHolder {

        private TextView titleTv;
        private TextView infoView;
        private TextView order_time;

        public ViewHolder(View itemView, OnItemClickListener listener) {
            super(itemView, listener);

            titleTv = (TextView) itemView.findViewById(R.id.msg_title);
            infoView = (TextView) itemView.findViewById(R.id.msg_info);
            order_time = (TextView) itemView.findViewById(R.id.order_time);
        }

    }
}
